package kr.hkit.powerjava.chapter25;

import java.io.*;
import java.net.*;

public class ParseURLExample {
	public static void main(String[] args) {
		try {
			StringBuilder sb = new StringBuilder();
			URL myURL = new URL("http://hkit.kr/SUB/?ctId=49&eduCode=00000027:80");
			sb.append("protocol = " + myURL.getProtocol()+"\n");
			sb.append("authority = " + myURL.getAuthority()+"\n");
			sb.append("host = " + myURL.getHost()+"\n");
			sb.append("port = " + myURL.getPort()+"\n");
			sb.append("path = " + myURL.getPath()+"\n");
			sb.append("query = " + myURL.getQuery()+"\n");
			sb.append("filename = " + myURL.getFile()+"\n");
			sb.append("ref = " + myURL.getRef()+"\n");
			System.out.println(sb);
			
			BufferedReader in = new BufferedReader(new InputStreamReader(myURL.openStream()));//두번째꺼 선택 try..
			String line;
			while((line=in.readLine()) !=null){
				System.out.println(line);
			}
			in.close();
		} catch (MalformedURLException e) {
			System.err.println("잘못된 주소입니다.");
		} catch (IOException e) {
		}
		
			/*URL url = new URL("http://hkit.kr/SUB/?ctId=49&eduCode=00000027");
*/	}
}
